package br.senac.sp.uniobjetos;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import br.senac.sp.persistence.AbstractRelationalDBMapper;
import br.senac.sp.persistence.unityofwork.Session;

public class TurmaMapper extends AbstractRelationalDBMapper<Turma, Integer> {

    public TurmaMapper(String tableName) {
        super(tableName);
    }

    @Override
    protected Turma getObjectFromRecord(Integer oid, ResultSet record)
            throws SQLException {
        Session session = new Session();
        Turma turma = new Turma();
        turma.setCurso(session.get(record.getInt("ID_CURSO"), Curso.class));
        turma.setDataInicio(record.getDate("DATA_INICIO"));
        turma.setDescricao(record.getString("DESCRICAO"));
        turma.setIdTurma(record.getInt("ID_TURMA"));
        return turma;
    }

    @Override
    protected Map<String, Object> getInfoFromObject(Turma entity) {
        Map<String, Object> info = new HashMap<String, Object>();
        info.put("ID_CURSO", entity.getCurso().getIdCurso());
        info.put("DATA_INICIO", entity.getDataInicio());
        info.put("DESCRICAO", entity.getDescricao());
        return info;
    }

    @Override
    protected Integer getIdFromObject(Turma entity) {
        return entity.getIdTurma();
    }

    @Override
    protected String getUniqueIdentifierArguments() {
        return "ID_TURMA"; 
    }

}
